package com.qmx.qmxapp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.qmx.qmxapp.R;
import com.qmx.qmxapp.base.BaseActivity;
import com.qmx.qmxapp.constant.AppConstant;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import mabbas007.tagsedittext.TagsEditText;

/**
 * @author ChengXiangtong
 * @create 2018/10/29
 * @Describe 参会人员
 */
public class ConfereeActivity extends BaseActivity {
    @BindView(R.id.iv_add)
    ImageView iv_add;
    @BindView(R.id.tagsEditText)
    TagsEditText tagsEditText;
    @BindView(R.id.btn_save)
    Button btn_save;

    private List<String> tags = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_conferee);
        ButterKnife.bind(this);
        tags.add(sharedPreferences.getString(AppConstant.USER_ID, ""));
        //        tags.add("我");

        tagsEditText.setTags(tags.toString());

    }

    @OnClick({R.id.iv_add, R.id.btn_save})
    public void onclick(View v) {
        switch (v.getId()) {
            case R.id.iv_add:
                startActivityForResult(new Intent(this, ContactGroupActivity.class), 1);
                break;
            case R.id.btn_save:
                Intent intent = new Intent(this, AppointmentMeetingActivity.class);
                intent.putStringArrayListExtra("uids", (ArrayList<String>) tags);
                setResult(2, intent);
                finish();
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if (requestCode == 1) {
            if (!data.getStringArrayListExtra("uids").isEmpty()) {
                tags = data.getStringArrayListExtra("uids");
                tagsEditText.setTags(tags.toString());
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}
